package com.bbm.bbmanage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bbm.bbmanage.entity.Property;
import com.bbm.bbmanage.entity.vo.ResponseResult;
import com.bbm.bbmanage.service.PropertyService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;

/**
 * (Property)表控制层
 *
 * @author lionkliu
 * @since 2024-03-23 18:40:05
 */
@RestController
@RequestMapping("property")
public class PropertyController {

    @Resource
    private PropertyService propertyService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return propertyService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/search")
    public ResponseResult search(
            @RequestParam(value = "name") String name,
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize) {
        return propertyService.search(pageNum, pageSize, name);
    }

    @GetMapping("{id}")
    public ResponseResult getPropertiesByHouseId(@PathVariable Long id) {
        return propertyService.getPropertiesByHouseId(id);
    }

    @GetMapping("/label")
    public ResponseResult getPropertiesLabelValue() {
        return propertyService.getPropertiesLabelValue();
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Property property) {
        return propertyService.insertOne(property);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Property property) {
        return propertyService.updateOne(property);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return propertyService.deleteById(id);
    }

}
